package cn.firecode.data_collect.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.context.request.WebRequest;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: yangfan
 * @Date: 2019/12/19
 * @Description:
 */
@RestControllerAdvice(annotations = RestController.class)
@Slf4j
public class DcsRestExceptionController {
    /**
     * 处理所有的Controller层面的异常
     * */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public final Map handleAllExceptions(Exception ex, WebRequest request){
        log.error(ex.getMessage());
        Map<String,Object> map=new HashMap<>();
        map.put("status",1);
        map.put("msg",ex.getLocalizedMessage());

        return map;
    }
}
